<template>
  <view class="u-wrap">
    <view class="u-search-box">
      <view class="u-search-inner" @click="gotosearch">
        <u-icon name="search" color="#909399" :size="28"></u-icon>
        <text class="u-search-text">请输入关键词进行搜索</text>
      </view>
    </view>
    <view class="u-menu-wrap">
      <view class="u-tab-view" style="height: 87.2%">
        <scroll-view scroll-y scroll-with-animation class="menu-scroll-view" :scroll-top="scrollTop" style="height: 100%">
  <!--        <view v-for="(item,index) in tabbar" :key="index" class="u-tab-item" :class="[current==index ? 'u-tab-item-active' : '']"-->
  <!--              :data-current="index" @tap.stop="swichMenu(index)">-->
  <!--          <text class="u-line-1">{{item.name}}</text>-->
  <!--        </view>-->

          <view v-for="(item,index) in leftData" :key="index" class="u-tab-item"
        :class="{changeStyle:changeSelectStyle == index}" @click="handover(index)">
            <text class="u-line-1">{{item.name}}</text>
          </view>
        </scroll-view>
      </view>
<!--      <block v-for="(item,index) in tabbar" :key="index">-->
<!--        <scroll-view scroll-y class="right-box" v-if="current==index">-->
<!--          <view class="page-view">-->
<!--            <view class="class-item">-->
<!--              <view class="item-title">-->
<!--                <text>{{item.name}}</text>-->
<!--              </view>-->
<!--              <view class="item-container">-->
<!--                <view class="thumb-box" v-for="(item1, index1) in item.foods" :key="index1">-->
<!--                  <image class="item-menu-image" :src="item1.icon" mode=""></image>-->
<!--                  <view class="item-menu-name">{{item1.name}}</view>-->
<!--                </view>-->
<!--              </view>-->
<!--            </view>-->
<!--          </view>-->
<!--        </scroll-view>-->
<!--      </block>-->
      <block>
        <view class="right-box">
        <scroll-view class="right-box-content" scroll-y :scroll-top="scrollTopTwo" @scrolltolower="bottomDown" @scrolltoupper="bottomUp">
          <view class="page-view" v-for="(item,index) in contentData" :key="index"
          :class="{changeStylebg:item.checked == true}">
          <!-- <view class="item-container">
            <view class="thumb-box"> -->
              <!-- <image class="item-menu-image"></image>
              <view class="item-menu-name">23223</view> -->
              <view class="box-top">
                <view class="top-time">
                  {{item.day}}
                </view>
              <view class="">
                <u-checkbox-group @change="Checked(index)">
                  <u-checkbox v-model="item.checked" shape="square" active-color="#FFC694"></u-checkbox>
                </u-checkbox-group>
              </view>
              </view>
              <view style="border: #FFC694 1rpx solid;width: 92%;margin: 0 auto;"></view>
              <view class="box-bottom">
                <view class="bottom-top">
                  {{item.title}}
                </view>
                <view class="bottom-content">
                  {{item.desc}}
                </view>
              </view>
          </view>
          <view class="page-view" v-if="showTotal">
            <view class="bottom-top" style="text-align: center">
              没有更多内容了
            </view>
          </view>
        </scroll-view>
        </view>
      </block>
    </view>
	<view class="bottom" @click="toPreview">
	  <view class="bottom_but">
	    <span class="bottom_but_text">内容预览</span>
	  </view>
	</view>
  </view>
</template>

<script>
import classifyData from "./classify.data.js";
export default {
  data() {
    return {
      tabbar: classifyData,
	    scrollTopTwo:0,
      scrollTop: 0, //tab标题的滚动条位置
      current: 0, // 预设当前项的值
      menuHeight: 0, // 左边菜单的高度
      menuItemHeight: 0, // 左边菜单item的高度
      changeSelectStyle:'',
      changeSelectStybg:'',
      leftData:[
        {name:'总要讲话'},
        {name:'会议活动'},
        {name:'考研调查'},
        {name:'考研调查'},
        {name:'考研调查'},
        {name:'考研调查'},
        {name:'考研调查'},
      ],
      checked:'',
      contentData:[],
      total:"",
      page:1,
      limit:10,
      showTotal:false,
      type_id:1
    }
  },
  computed: {

  },
  mounted(){
    this.getRiliType()
    this.getRiliContent()
  },
  methods: {
    async getRiliType() {
      let params = {
        "login_token": uni.getStorageSync('loginToken'),
      }
      let res = await this.$api.getContentRiliTypeList(params)
      if (res.data.level == "success") {
        this.leftData = res.data.data;

      } else {
        uni.showToast({
          title: res.data.message,
          icon: 'none'
        })
      }
    },
    async getRiliContent() {
      let params = {
        "login_token": uni.getStorageSync('loginToken'),
        "page": this.page,
        "limit": this.limit,
        "type_id": this.type_id
      }

      uni.showLoading({
        title: '加载中'
      });
      let res = await this.$api.getGeneralContentList(params)
      uni.hideLoading();
      if (res.data.level == "success") {
        this.contentData = res.data.data;
        // this.total = res.data.page_info.total
        this.total = Math.ceil(res.data.total / this.page);
      } else {
        uni.showToast({
          title: res.data.message,
          icon: 'none'
        })
      }
    },
    bottomDown() {
      if (this.page >= this.total) {
        this.showTotal = true
        return false;
      }
      this.page++;
      this.getRiliContent();
    },
    bottomUp() {
      if (this.page < this.total) {
        this.showTotal = false
        return false;
      }
      this.page--;
      this.getRiliContent();
    },
    // getImg() {
    //   return Math.floor(Math.random() * 35);
    // },
    // 点击左边的栏目切换
    async swichMenu(index) {
      if (index == this.current) return;
      this.current = index;
      // 如果为0，意味着尚未初始化
      if (this.menuHeight == 0 || this.menuItemHeight == 0) {
        await this.getElRect('menu-scroll-view', 'menuHeight');
        await this.getElRect('u-tab-item', 'menuItemHeight');
      }
      // 将菜单菜单活动item垂直居中
      this.scrollTop = index * this.menuItemHeight + this.menuItemHeight / 2 - this.menuHeight / 2;
    },
    // 获取一个目标元素的高度
    getElRect(elClass, dataVal) {
      new Promise((resolve, reject) => {
        const query = uni.createSelectorQuery().in(this);
        query.select('.' + elClass).fields({size: true}, res => {
          // 如果节点尚未生成，res值为null，循环调用执行
          if (!res) {
            setTimeout(() => {
              this.getElRect(elClass);
            }, 10);
            return;
          }
          this[dataVal] = res.height;
        }).exec();
      })
    },

    handover(index) {
      this.scrollTopTwo = this.scrollTopTwo == 0 ? -1 : 0
      this.changeSelectStyle = index

      this.type_id = this.leftData[index].id;
      this.page = 1;
      this.getRiliContent();
    },
    Checked(index) {
      let actionType = ''
      let generalId = this.contentData[index].id
      if (this.contentData[index].checked) {
        actionType = 'add'
      } else {
        actionType = 'del'
      }

      this.setContentToProgramme(actionType, generalId, index)
    },
    async setContentToProgramme(actionType, generalId, index) {
      let params = {
        "login_token": uni.getStorageSync('loginToken'),
        "general_id": generalId,
        "action_type": actionType,
      }

      let res = await this.$api.setGeneralContentOneToProgrammeContent(params)
      if (res.data.level == "success") {
        this.changeSelectStybg = index
      } else {
        uni.showToast({
          title: res.data.message,
          icon: 'none'
        })
      }
    },
    gotosearch() {
      uni.navigateTo({
        url: '/pages/general/search'
      })
    },
    toPreview() {
      uni.navigateTo({
        url: '/pages/contentPreview/preview?model_type=general_content'
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.u-wrap {
  height: calc(100vh);
  /* #ifdef H5 */
  height: calc(100vh - var(--window-top));
  /* #endif */
  display: flex;
  flex-direction: column;
  background-color: #EBB27F;
}

.u-search-box {
  padding: 18rpx 30rpx;
  background: #91150F;
}

.u-menu-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
  background-color: #EBB27F;
}

.u-search-inner {
  background-color: rgb(234, 234, 234);
  border-radius: 50rpx;
  display: flex;
  align-items: center;
  padding: 10rpx 16rpx;
}

.u-search-text {
  font-size: 26rpx;
  color: $u-tips-color;
  margin-left: 10rpx;
}

.u-tab-view {
  margin-top: 20rpx;
  width: 333rpx;
  height: 90%;
  background: #91150F;
}

.u-tab-item {
  height: 90rpx;
  background: #91150F;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26rpx;
  color: #FFC694;
  font-weight: 400;
  line-height: 1;
}

.u-tab-item-active {
  position: relative;
  color: #FFC694;
  font-size: 30rpx;
  font-weight: 600;
  background: #7F090B;
}

//.u-tab-item-active::before {
//  content: "";
//  position: absolute;
//  border-left: 4px solid $u-type-primary;
//  height: 32rpx;
//  left: 0;
//  top: 39rpx;
//}

//.u-tab-view {
//  height: 100%;
//}

.right-box {
  //background-color: rgb(250, 250, 250);
  background-color: #EBB27F;
  display: flex;
  flex-direction: column;
  //justify-content: center;
  align-items:center;
  margin-left: 30rpx;
  height: 87.2%;
  margin-top: 20rpx;
  width: 960rpx;
}
.right-box-content{
  height: 100%
}
.page-view {
  margin-bottom: 20rpx;
  //padding: 16rpx;
  background-color: #91150F;
  width: 95%;

}

.class-item {
  margin-bottom: 30rpx;
  background-color: #fff;
  padding: 16rpx;
  border-radius: 8rpx;
}

.item-title {
  font-size: 26rpx;
  color: $u-main-color;
  font-weight: bold;
}

.item-menu-name {
  font-weight: normal;
  font-size: 24rpx;
  color: $u-main-color;
}

.item-container {
  display: flex;
  flex-wrap: wrap;
}

.thumb-box {
  width: 33.333333%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  margin-top: 20rpx;
}

.box-top{
	padding: 28rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	color: #FFD4A5;
}
.item-menu-image {
  width: 120rpx;
  height: 120rpx;
}

//.uni-scroll-view-content{
//  background-color: #EBB27F !important;
//}

.changeStyle{
	position: relative;
	color: #FFC694;
	font-size: 30rpx;
	font-weight: 600;
	background: #7F090B;
}
.box-bottom{
	padding: 28rpx;
}
.bottom-top{
	padding-bottom: 25rpx;
	color: #FFD4A5;
	font-size: 30rpx;
}
.bottom-content{
	color: #bd9d81;
	font-size: 29rpx;
	line-height: 35rpx;
	
	text-overflow: -o-ellipsis-lastline;
	 overflow: hidden;
	 text-overflow: ellipsis;
	 display: -webkit-box;
	 -webkit-line-clamp: 3;
	 line-clamp: 3;
	 -webkit-box-orient: vertical;
}
  .bottom{
    background-color: #FFC18A;
    border-top: #93110A solid 1rpx;
    position: fixed;
    bottom: 0;
    // left: 0;
    height: 130rpx;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .bottom_but{
    background-image: url(../../static/img/login_imgTwo.png);
    background-repeat: no-repeat;
    height: 100rpx;
    background-size: 100% 100%;
    width: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #FFC695;
  }
  .changeStylebg{
	margin-top: 20rpx;
	//padding: 16rpx;
	background-color: #7F090B;
	width: 95%;
  }
</style>
